-- LevelTerrainManager.lua
-- 关卡地形管理器：管理斜坡、缺口、墙壁等特殊地形
-- 斜坡作为倾斜平台，无滑落功能

local LevelTerrainManager = {}
LevelTerrainManager.__index = LevelTerrainManager

local LevelTileConfig = require("LevelTileConfig")

-- 地形类型定义
local TerrainType = {
    NORMAL = "normal",      -- 正常地面
    GAP = "gap",           -- 缺口
    SLOPE = "slope",       -- 斜坡（倾斜平台）
    WALL = "wall",         -- 墙壁
    PLATFORM = "platform", -- 平台
    BOSS_TRIGGER = "boss_trigger" -- Boss触发器
}

function LevelTerrainManager.new()
    local instance = {
        terrainData = {},          -- 地形数据缓存
        activeTerrain = {},        -- 当前激活的地形
        collisionPlatforms = {},   -- 碰撞平台（用于物理检测）
        debugMode = true,
        _gapData = {},              -- 专门存储缺口数据
        _bossTriggerData = nil,     -- Boss触发器数据
        _onBossTriggerCallback = nil -- Boss触发器回调
    }
    
    return setmetatable(instance, LevelTerrainManager)
end

-- 初始化所有地形数据
function LevelTerrainManager:initialize()
    print("初始化关卡地形数据...")
    
    -- 清除现有数据
    self.terrainData = {}
    self.collisionPlatforms = {}
    self._gapData = {}
    self._bossTriggerData = nil
    
    -- 创建所有切片的基础地形
    self:createBaseTerrain()
    
    -- 添加特殊地形（根据需求）
    self:addSpecialTerrain()
    
    -- 创建碰撞平台（排除缺口）
    self:createCollisionPlatforms()
    
    print("地形数据初始化完成，共创建 " .. #self.collisionPlatforms .. " 个碰撞平台")
    
    if self.debugMode then
        self:printTerrainSummary()
    end
    
    return true
end

-- 创建所有切片的基础地形
function LevelTerrainManager:createBaseTerrain()
    for row = 1, LevelTileConfig.GRID_SIZE.rows do
        for col = 1, LevelTileConfig.GRID_SIZE.cols do
            local tileIndex = LevelTileConfig.getTileIndex(row, col)
            local tileInfo = LevelTileConfig.tilePositions[tileIndex]
            
            if tileInfo then
                -- 创建基础地面
                local groundPlatform = {
                    type = TerrainType.NORMAL,
                    row = row,
                    col = col,
                    x = tileInfo.x,
                    y = tileInfo.groundY,  -- 使用切片的地面高度（y=320处）
                    width = LevelTileConfig.TILE_SIZE.width,
                    height = 50,  -- 地面厚度
                    tileInfo = tileInfo,
                    isWalkable = true,
                    isSlope = false
                }
                
                -- 存储地形数据
                local key = string.format("%d_%d_base", row, col)
                self.terrainData[key] = groundPlatform
            end
        end
    end
end

-- 添加特殊地形
function LevelTerrainManager:addSpecialTerrain()
    print("添加特殊地形...")
    
    -- 1. 01_01的缺口 (870到2370像素区间)
    self:addGap(1, 1, 870, 2370)
    
    -- 2. 01_01到02_02的斜坡
    self:addSlope({
        startTile = {row = 1, col = 1},
        endTile = {row = 2, col = 2},
        startX = 870,  -- 从01_01的缺口左侧开始
        endX = 500     -- 到02_02的500像素处
    })
    
    -- 3. 01_09的缺口 (30到1520)
    self:addGap(1, 9, 30, 1520)
    
    -- 4. 01_09到02_08的斜坡
    self:addSlope({
        startTile = {row = 1, col = 9},
        endTile = {row = 2, col = 8},
        startX = 1520,  -- 从01_09的缺口右侧开始
        endX = 2210     -- 到02_08的2210像素处
    })
    
    -- 5. 02_05的墙壁 (660到2400)
    self:addWall(2, 5, 660, 2400)
    
    -- 6. 02_03的缺口 (805到1380) - 这里下方是Boss关卡入口
    self:addGap(2, 3, 805, 1380)
    
    -- 7. 03_05的墙壁 (70到1540)
    self:addWall(3, 5, 70, 1540)
    
    -- 8. 03_09的缺口 (15到1360)
    self:addGap(3, 9, 15, 1360)
    
    -- 9. 03_09到04_08的斜坡
    self:addSlope({
        startTile = {row = 3, col = 9},
        endTile = {row = 4, col = 8},
        startX = 1360,  -- 从03_09的缺口右侧开始
        endX = 1955     -- 到04_08的1955像素处
    })
    
    -- 10. 04_04的缺口 (650到2230)
    self:addGap(4, 4, 650, 2230)
    
    -- 11. 04_04到05_03的斜坡
    self:addSlope({
        startTile = {row = 4, col = 4},
        endTile = {row = 5, col = 3},
        startX = 2230,  -- 从04_04的缺口右侧开始
        endX = 2280     -- 到05_03的2280像素处
    })
    
    -- 12. 添加Boss关卡触发器（在02_03缺口下方）
    self:addBossTrigger(2, 3, 805, 1380)
    
    print("特殊地形添加完成")
end

-- 添加缺口
function LevelTerrainManager:addGap(row, col, startX, endX)
    local tileInfo = self:getTileInfo(row, col)
    if not tileInfo then return false end
    
    -- 计算缺口在切片内的相对位置
    local tileStartX = tileInfo.x
    local absoluteStartX = tileStartX + startX
    local absoluteEndX = tileStartX + endX
    
    -- 创建缺口数据
    local gapData = {
        type = TerrainType.GAP,
        row = row,
        col = col,
        x = absoluteStartX,
        y = tileInfo.groundY,
        width = endX - startX,
        height = 50,
        isWalkable = false,  -- 不可行走
        tileInfo = tileInfo
    }
    
    local key = string.format("%d_%d_gap_%d_%d", row, col, startX, endX)
    self.terrainData[key] = gapData
    
    -- 专门存储缺口数据
    table.insert(self._gapData, {
        x = absoluteStartX,
        y = tileInfo.groundY,
        width = endX - startX,
        row = row,
        col = col
    })
    
    -- 调整基础地面
    self:splitGroundForGap(row, col, startX, endX, tileInfo)
    
    if self.debugMode then
        print(string.format("添加缺口: %02d_%02d, X范围: %d-%d (绝对: %.1f-%.1f)", 
            row, col, startX, endX, absoluteStartX, absoluteEndX))
    end
    
    return true
end

-- 为缺口分割地面
function LevelTerrainManager:splitGroundForGap(row, col, gapStartX, gapEndX, tileInfo)
    local tileStartX = tileInfo.x
    local tileWidth = LevelTileConfig.TILE_SIZE.width
    
    -- 左侧地面（如果存在）
    if gapStartX > 0 then
        local leftGround = {
            type = TerrainType.NORMAL,
            row = row,
            col = col,
            x = tileStartX,
            y = tileInfo.groundY,
            width = gapStartX,
            height = 50,
            isWalkable = true,
            tileInfo = tileInfo,
            isLeftSegment = true
        }
        
        local leftKey = string.format("%d_%d_base_left", row, col)
        self.terrainData[leftKey] = leftGround
    end
    
    -- 右侧地面（如果存在）
    if gapEndX < tileWidth then
        local rightGround = {
            type = TerrainType.NORMAL,
            row = row,
            col = col,
            x = tileStartX + gapEndX,
            y = tileInfo.groundY,
            width = tileWidth - gapEndX,
            height = 50,
            isWalkable = true,
            tileInfo = tileInfo,
            isRightSegment = true
        }
        
        local rightKey = string.format("%d_%d_base_right", row, col)
        self.terrainData[rightKey] = rightGround
    end
    
    -- 移除原来的完整地面
    local baseKey = string.format("%d_%d_base", row, col)
    self.terrainData[baseKey] = nil
end

-- 添加斜坡（作为倾斜平台）
function LevelTerrainManager:addSlope(params)
    local startTileInfo = self:getTileInfo(params.startTile.row, params.startTile.col)
    local endTileInfo = self:getTileInfo(params.endTile.row, params.endTile.col)
    
    if not startTileInfo or not endTileInfo then return false end
    
    -- 斜坡起点和终点都在各自切片的地面高度（y=320处）
    local absoluteStartX = startTileInfo.x + params.startX
    local absoluteEndX = endTileInfo.x + params.endX
    local absoluteStartY = startTileInfo.groundY
    local absoluteEndY = endTileInfo.groundY
    
    -- 创建斜坡数据（作为倾斜平台）
    local slopeData = {
        type = TerrainType.SLOPE,
        startRow = params.startTile.row,
        startCol = params.startTile.col,
        endRow = params.endTile.row,
        endCol = params.endTile.col,
        x = math.min(absoluteStartX, absoluteEndX),
        y = math.min(absoluteStartY, absoluteEndY),
        width = math.abs(absoluteEndX - absoluteStartX),
        height = math.abs(absoluteEndY - absoluteStartY),
        startX = absoluteStartX,
        startY = absoluteStartY,
        endX = absoluteEndX,
        endY = absoluteEndY,
        isWalkable = true,
        isSlope = true,
        
        -- 斜坡的线性函数参数: y = kx + b
        k = (absoluteEndY - absoluteStartY) / (absoluteEndX - absoluteStartX),
        b = absoluteStartY - ((absoluteEndY - absoluteStartY) / (absoluteEndX - absoluteStartX)) * absoluteStartX
    }
    
    local key = string.format("slope_%d_%d_to_%d_%d", 
        params.startTile.row, params.startTile.col,
        params.endTile.row, params.endTile.col)
    
    self.terrainData[key] = slopeData
    
    if self.debugMode then
        print(string.format("添加斜坡（倾斜平台）: %02d_%02d(%.1f,%.1f) -> %02d_%02d(%.1f,%.1f)", 
            params.startTile.row, params.startTile.col, absoluteStartX, absoluteStartY,
            params.endTile.row, params.endTile.col, absoluteEndX, absoluteEndY))
        print(string.format("  斜率: %.4f", slopeData.k))
    end
    
    return true
end

-- 添加墙壁
function LevelTerrainManager:addWall(row, col, startX, endX)
    local tileInfo = self:getTileInfo(row, col)
    if not tileInfo then return false end
    
    -- 计算墙壁在切片内的相对位置
    local tileStartX = tileInfo.x
    local absoluteStartX = tileStartX + startX
    local absoluteEndX = tileStartX + endX
    
    -- 创建墙壁数据
    local wallData = {
        type = TerrainType.WALL,
        row = row,
        col = col,
        x = absoluteStartX,
        y = tileInfo.bottomBound,  -- 从切片底部开始
        width = endX - startX,
        height = tileInfo.topBound - tileInfo.bottomBound,  -- 整个切片高度
        isWalkable = false,  -- 不可行走
        tileInfo = tileInfo
    }
    
    local key = string.format("%d_%d_wall_%d_%d", row, col, startX, endX)
    self.terrainData[key] = wallData
    
    if self.debugMode then
        print(string.format("添加墙壁: %02d_%02d, X范围: %d-%d, 高度: %.1f", 
            row, col, startX, endX, wallData.height))
    end
    
    return true
end

-- 添加Boss关卡触发器
function LevelTerrainManager:addBossTrigger(row, col, startX, endX)
    local tileInfo = self:getTileInfo(row, col)
    if not tileInfo then return false end
    
    -- 计算触发器位置：在缺口的正下方
    local tileStartX = tileInfo.x
    local gapCenterX = tileStartX + (startX + endX) / 2
    
    -- 触发器在缺口下方一定距离处
    local triggerY = tileInfo.groundY - 900  -- 缺口下方200像素
    
    -- 创建触发器数据
    local triggerData = {
        type = TerrainType.BOSS_TRIGGER,
        row = row,
        col = col,
        x = gapCenterX,
        y = triggerY,
        width = 100,  -- 触发器宽度
        height = 50,
        isWalkable = true,  -- 可以站在上面
        triggerBossScene = true,
        tileInfo = tileInfo,
        originalGapStartX = startX,
        originalGapEndX = endX
    }
    
    local key = string.format("%d_%d_boss_trigger", row, col)
    self.terrainData[key] = triggerData
    
    self._bossTriggerData = triggerData
    
    if self.debugMode then
        print(string.format("添加Boss关卡触发器: %02d_%02d, 位置: (%.1f, %.1f), 缺口: %d-%d", 
            row, col, gapCenterX, triggerY, startX, endX))
    end
    
    return true
end

-- 创建碰撞平台（用于物理检测）- 修复版
function LevelTerrainManager:createCollisionPlatforms()
    print("创建碰撞平台...")
    
    -- 清空现有平台
    self.collisionPlatforms = {}
    
    -- 只添加可行走的地形（排除缺口）
    for key, terrain in pairs(self.terrainData) do
        if terrain.isWalkable and terrain.type ~= TerrainType.GAP then
            local platform = {
                x = terrain.x,
                y = terrain.y,
                width = terrain.width,
                height = terrain.height or 50,
                row = terrain.row,
                col = terrain.col,
                terrainType = terrain.type,
                terrainData = terrain,
                isSlope = terrain.isSlope or false,
                slopeData = terrain.isSlope and terrain or nil,
                isWalkable = true
            }
            
            -- 如果是Boss触发器，添加特殊标记
            if terrain.type == TerrainType.BOSS_TRIGGER then
                platform.isBossTrigger = true
                platform.triggerData = terrain
            end
            
            table.insert(self.collisionPlatforms, platform)
        end
    end
    
    -- 添加缺口作为非可行走区域（用于调试）
    for _, gap in ipairs(self._gapData) do
        local gapPlatform = {
            x = gap.x,
            y = gap.y,
            width = gap.width,
            height = 50,
            isWalkable = false,
            isGap = true,
            row = gap.row,
            col = gap.col
        }
        table.insert(self.collisionPlatforms, gapPlatform)
    end
    
    print("碰撞平台创建完成，共 " .. #self.collisionPlatforms .. " 个")
    if self.debugMode then
        print("其中缺口数量: " .. #self._gapData)
        if self._bossTriggerData then
            print("Boss触发器: 1 个")
        end
    end
end

-- 检查位置是否可行走 - 修复版
function LevelTerrainManager:isWalkable(x, y, characterRadius)
    characterRadius = characterRadius or 25
    local characterBottom = y - characterRadius
    
    -- 首先检查是否在缺口上
    for _, platform in ipairs(self.collisionPlatforms) do
        if platform.isGap then
            -- 检查是否在缺口范围内
            if x >= platform.x - characterRadius and x <= platform.x + platform.width + characterRadius then
                local platformTop = platform.y + platform.height
                
                -- 如果角色在缺口上方附近，返回false
                if characterBottom >= platformTop - 30 and characterBottom <= platformTop + 10 then
                    return false
                end
            end
        end
    end
    
    -- 检查Boss触发器
    for _, platform in ipairs(self.collisionPlatforms) do
        if platform.isBossTrigger then
            -- 检查是否在触发器范围内
            if x >= platform.x - characterRadius and x <= platform.x + platform.width + characterRadius then
                local platformTop = platform.y + platform.height
                
                -- 如果角色在触发器上方附近
                if characterBottom >= platformTop - 30 and characterBottom <= platformTop + 10 then
                    -- 触发Boss关卡
                    self:triggerBossScene(platform.triggerData)
                    return true  -- 仍然可以站立
                end
            end
        end
    end
    
    -- 检查斜坡
    for _, platform in ipairs(self.collisionPlatforms) do
        if platform.isSlope and platform.slopeData then
            local slope = platform.slopeData
            
            local minX = math.min(slope.startX, slope.endX) - characterRadius * 2
            local maxX = math.max(slope.startX, slope.endX) + characterRadius * 2
            
            if x >= minX and x <= maxX then
                local groundY = slope.k * x + slope.b
                
                -- 放宽斜坡接触检测范围
                if characterBottom >= groundY - 25 and characterBottom <= groundY + 25 then
                    return true
                end
            end
        end
    end
    
    -- 检查普通平台
    for _, platform in ipairs(self.collisionPlatforms) do
        if not platform.isSlope and not platform.isGap and not platform.isBossTrigger and platform.isWalkable then
            -- 放宽水平检测范围
            if x >= platform.x - characterRadius * 2 and x <= platform.x + platform.width + characterRadius * 2 then
                local platformTop = platform.y + platform.height
                
                -- 放宽垂直检测范围
                if characterBottom >= platformTop - 30 and characterBottom <= platformTop + 10 then
                    return true
                end
            end
        end
    end
    
    return false
end

-- 检查是否在斜坡上 - 修复版
function LevelTerrainManager:isOnSlope(x, y, characterRadius)
    characterRadius = characterRadius or 25
    local characterBottom = y - characterRadius
    
    for _, platform in ipairs(self.collisionPlatforms) do
        if platform.isSlope and platform.slopeData then
            local slope = platform.slopeData
            
            local minX = math.min(slope.startX, slope.endX) - characterRadius * 2
            local maxX = math.max(slope.startX, slope.endX) + characterRadius * 2
            
            if x >= minX and x <= maxX then
                local groundY = slope.k * x + slope.b
                
                -- 放宽斜坡接触检测范围
                if math.abs(characterBottom - groundY) < 30 then
                    return true, slope
                end
            end
        end
    end
    
    return false, nil
end

-- 检查是否有墙壁阻挡
function LevelTerrainManager:isWallBlocked(x, y, direction, characterRadius)
    characterRadius = characterRadius or 25
    
    for key, terrain in pairs(self.terrainData) do
        if terrain.type == TerrainType.WALL then
            -- 检查是否在墙壁的X范围内
            if x >= terrain.x - characterRadius and x <= terrain.x + terrain.width + characterRadius then
                -- 检查是否在墙壁的Y范围内
                if y >= terrain.y and y <= terrain.y + terrain.height then
                    return true
                end
            end
        end
    end
    
    return false
end

-- 根据角色位置获取应站立的地面 - 修复版
function LevelTerrainManager:getStandingPlatform(x, y, characterRadius)
    characterRadius = characterRadius or 25
    local characterBottom = y - characterRadius
    
    -- 先检查是否在缺口上（如果是缺口，返回nil）
    for _, platform in ipairs(self.collisionPlatforms) do
        if platform.isGap then
            if x >= platform.x - characterRadius and x <= platform.x + platform.width + characterRadius then
                local platformTop = platform.y + platform.height
                if characterBottom >= platformTop - 30 and characterBottom <= platformTop + 10 then
                    return nil  -- 在缺口上，没有站立平台
                end
            end
        end
        
        -- 检查Boss触发器
        if platform.isBossTrigger then
            if x >= platform.x - characterRadius and x <= platform.x + platform.width + characterRadius then
                local platformTop = platform.y + platform.height
                if characterBottom >= platformTop - 30 and characterBottom <= platformTop + 10 then
                    return {
                        type = "boss_trigger",
                        x = platform.x,
                        y = platformTop,
                        width = platform.width,
                        height = platform.height,
                        triggerData = platform.triggerData,
                        isSlope = false
                    }
                end
            end
        end
    end
    
    -- 检查斜坡
    local onSlope, slope = self:isOnSlope(x, y, characterRadius)
    if onSlope and slope then
        local groundY = slope.k * x + slope.b
        return {
            type = "slope",
            x = slope.x,
            y = groundY,  -- 斜坡上的实际Y坐标
            width = slope.width,
            height = 10,
            slopeData = slope,
            isSlope = true
        }
    end
    
    -- 检查普通平台
    for _, platform in ipairs(self.collisionPlatforms) do
        if not platform.isSlope and not platform.isGap and not platform.isBossTrigger and platform.isWalkable then
            -- 检查水平对齐
            if x >= platform.x - characterRadius * 2 and x <= platform.x + platform.width + characterRadius * 2 then
                local platformTop = platform.y + platform.height
                
                -- 检查垂直距离
                if characterBottom >= platformTop - 30 and characterBottom <= platformTop + 5 then
                    return {
                        type = "platform",
                        x = platform.x,
                        y = platformTop,
                        width = platform.width,
                        height = platform.height,
                        row = platform.row,
                        col = platform.col,
                        isSlope = false
                    }
                end
            end
        end
    end
    
    return nil
end

-- 触发Boss关卡
function LevelTerrainManager:triggerBossScene(triggerData)
    if self._bossSceneTriggered then return end  -- 防止重复触发
    
    self._bossSceneTriggered = true
    
    print("====================================")
    print("触发BOSS关卡！")
    print(string.format("触发器位置: (%.1f, %.1f)", triggerData.x, triggerData.y))
    print(string.format("关联缺口: %02d_%02d的%d-%d像素", 
        triggerData.row, triggerData.col, 
        triggerData.originalGapStartX, triggerData.originalGapEndX))
    print("====================================")
    
    -- 触发回调
    if self._onBossTriggerCallback then
        self._onBossTriggerCallback(triggerData)
    end
end

-- 设置Boss关卡触发回调
function LevelTerrainManager:setBossTriggerCallback(callback)
    self._onBossTriggerCallback = callback
    print("地形管理器：设置Boss触发器回调")
end

-- 重置Boss触发器状态
function LevelTerrainManager:resetBossTrigger()
    self._bossSceneTriggered = false
    print("地形管理器：Boss触发器状态已重置")
end

-- 获取切片信息
function LevelTerrainManager:getTileInfo(row, col)
    local tileIndex = LevelTileConfig.getTileIndex(row, col)
    return LevelTileConfig.tilePositions[tileIndex]
end

-- 获取所有碰撞平台（用于运动系统）
function LevelTerrainManager:getCollisionPlatforms()
    return self.collisionPlatforms
end

-- 获取地形数据
function LevelTerrainManager:getTerrainData()
    return self.terrainData
end

-- 获取Boss触发器数据
function LevelTerrainManager:getBossTriggerData()
    return self._bossTriggerData
end

-- 根据位置激活地形
function LevelTerrainManager:updateActiveTerrain(playerX, playerY)
    self.activeTerrain = {}
    
    -- 获取玩家所在的切片
    local row, col = LevelTileConfig.getTileByPosition(playerX, playerY)
    
    if not row or not col then return end
    
    -- 激活3x3区域内的地形
    for r = math.max(1, row-1), math.min(LevelTileConfig.GRID_SIZE.rows, row+1) do
        for c = math.max(1, col-1), math.min(LevelTileConfig.GRID_SIZE.cols, col+1) do
            self:activateTileTerrain(r, c)
        end
    end
end

-- 激活切片地形
function LevelTerrainManager:activateTileTerrain(row, col)
    -- 查找该切片的所有地形
    for key, terrain in pairs(self.terrainData) do
        if (terrain.row == row and terrain.col == col) or
           (terrain.startRow == row and terrain.startCol == col) or
           (terrain.endRow == row and terrain.endCol == col) then
            self.activeTerrain[key] = terrain
        end
    end
end

-- 打印地形摘要
function LevelTerrainManager:printTerrainSummary()
    print("=== 地形数据摘要 ===")
    
    local counts = {
        normal = 0,
        gap = 0,
        slope = 0,
        wall = 0,
        platform = 0,
        boss_trigger = 0
    }
    
    for key, terrain in pairs(self.terrainData) do
        if terrain.type then
            counts[terrain.type] = (counts[terrain.type] or 0) + 1
        end
    end
    
    for typeName, count in pairs(counts) do
        print(string.format("%s: %d", typeName, count))
    end
    
    print("=== 特殊地形详情 ===")
    
    -- 打印所有缺口
    for _, gap in ipairs(self._gapData) do
        print(string.format("缺口: %02d_%02d, 位置: %.1f, 宽度: %.1f",
            gap.row, gap.col, gap.x, gap.width))
    end
    
    -- 打印所有斜坡
    for key, terrain in pairs(self.terrainData) do
        if terrain.type == TerrainType.SLOPE then
            print(string.format("斜坡（倾斜平台）: %02d_%02d -> %02d_%02d, 长度: %.1f, 斜率: %.4f",
                terrain.startRow, terrain.startCol,
                terrain.endRow, terrain.endCol,
                terrain.width, terrain.k))
        elseif terrain.type == TerrainType.WALL then
            print(string.format("墙壁: %02d_%02d, 宽度: %.1f, 高度: %.1f",
                terrain.row, terrain.col, terrain.width, terrain.height))
        elseif terrain.type == TerrainType.BOSS_TRIGGER then
            print(string.format("Boss触发器: %02d_%02d, 位置: (%.1f, %.1f), 关联缺口: %d-%d",
                terrain.row, terrain.col, terrain.x, terrain.y,
                terrain.originalGapStartX, terrain.originalGapEndX))
        end
    end
    
    print("====================")
end

-- 清理资源
function LevelTerrainManager:cleanup()
    self.terrainData = {}
    self.activeTerrain = {}
    self.collisionPlatforms = {}
    self._gapData = {}
    self._bossTriggerData = nil
    self._onBossTriggerCallback = nil
    self._bossSceneTriggered = false
    
    print("地形管理器资源清理完成")
end

return LevelTerrainManager